Function definitions
functiondefinition
A function definition defines a user-defined function object (see
section
):
user-defined function
function
funcdef: "def" funcname "(" [parameter_list] ")" ":" suite
parameter_list: (defparameter ",")* ("*" identifier | defparameter [","])
defparameter: parameter ["=" condition]
sublist: parameter ("," parameter)* [","]
parameter: identifier | "(" sublist ")"
funcname: identifier
A function definition is an executable statement. Its execution binds
the function name in the current local name space to a function object
(a wrapper around the executable code for the function). This
function object contains a reference to the current global name space
as the global name space to be used when the function is called.
functionname
namebinding
The function definition does not execute the function body; this gets
executed only when the function is called.
When one or more top-level parameters have the form parameter =
condition, the function is said to have ``default parameter values''.
Default parameter values are evaluated when the function definition is
executed. For a parameter with a default value, the correponding
argument may be omitted from a call, in which case the parameter's
default value is substituted. If a parameter has a default value, all
following parameters must also have a default value — this is a
syntactic restriction that is not expressed by the grammar.